package com.itheima.d5_inner_class5;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test {
    public static void main(String[] args) {
        // 拓展: 搞清楚匿名内部类在开发中的真实使用场景
        // GUI编程 (桌面编程)

        JFrame win = new JFrame("登录界面");
        JPanel panel = new JPanel();
        JButton btn = new JButton("登录");
        // 给按钮添加绑定单机事件监听器
//        btn.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                JOptionPane.showMessageDialog(win, "我点击了登录");
//            }
//        });

        btn.addActionListener(e -> JOptionPane.showMessageDialog(win, "我点击了登录"));

        panel.add(btn);
        win.add(panel);
        win.setSize(400, 400);
        win.setLocationRelativeTo(null); // 居中
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        win.setVisible(true);
    }
}
